<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ShredTheLog.Controls">

    <PathGeometry x:Key="CloseWindowGeometry">
        <PathFigure StartPoint="-1, -1">
            <LineSegment Point="-0.8, -1"/>
            <LineSegment Point="0, -0.2"/>
            <LineSegment Point="0.8, -1"/>
            <LineSegment Point="1, -1"/>
            <LineSegment Point="1, -0.8"/>
            <LineSegment Point="0.2, 0"/>
            <LineSegment Point="1, 0.8"/>
            <LineSegment Point="1, 1"/>
            <LineSegment Point="0.8, 1"/>
            <LineSegment Point="0, 0.2"/>
            <LineSegment Point="-0.8, 1"/>
            <LineSegment Point="-1, 1"/>
            <LineSegment Point="-1, 0.8"/>
            <LineSegment Point="-0.2, 0"/>
            <LineSegment Point="-1, -0.8"/>
        </PathFigure>
    </PathGeometry>

    <GeometryGroup x:Key="MinimizeWindowGeometry">
        <RectangleGeometry Rect="0, 0, 0, 0"/>
        <RectangleGeometry Rect="0, 0.8, 1, 0.2"/>
    </GeometryGroup>
    
    <CombinedGeometry x:Key="MaximizeWindowGeometry" GeometryCombineMode="Exclude">
        <CombinedGeometry.Geometry1>
            <RectangleGeometry Rect="0, 0, 1, 1"/>
        </CombinedGeometry.Geometry1>
        <CombinedGeometry.Geometry2>
            <RectangleGeometry Rect="0.1, 0.2, 0.8, 0.7"/>
        </CombinedGeometry.Geometry2>
    </CombinedGeometry>
    
    <GeometryGroup x:Key="NormalizeWindowGeometry">
        <CombinedGeometry GeometryCombineMode="Exclude">
            <CombinedGeometry.Geometry1>
                <RectangleGeometry Rect="0, 0, 1, 1"/>
            </CombinedGeometry.Geometry1>
            <CombinedGeometry.Geometry2>
                <RectangleGeometry Rect="0.1, 0.2, 0.8, 0.7"/>
            </CombinedGeometry.Geometry2>
        </CombinedGeometry>
        <PathGeometry>
            <PathFigure StartPoint="0.5, 0">
                <LineSegment Point="0.5, -0.5"/>
                <LineSegment Point="1.5, -0.5"/>
                <LineSegment Point="1.5, 0.5"/>
                <LineSegment Point="1, 0.5"/>
                <LineSegment Point="1, 0.4"/>
                <LineSegment Point="1.4, 0.4"/>
                <LineSegment Point="1.4, -0.3"/>
                <LineSegment Point="0.6, -0.3"/>
                <LineSegment Point="0.6, 0"/>
            </PathFigure>
        </PathGeometry>
    </GeometryGroup>



    <Style TargetType="{x:Type local:FilePicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:FilePicker}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            
                            <TextBox 
                                Grid.Column="0" 
                                Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Button Grid.Column="1" Content="..." Command="{TemplateBinding BrowseCommand}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ColorPicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ColorPicker}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <Viewbox Grid.Column="0" Height="{Binding ElementName=textBox, Path=ActualHeight, Mode=OneWay}">
                                <Border 
                                    Width="20" 
                                    Height="20" 
                                    Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=OneWay, Converter={x:Static local:ColorToBrushConverter.Default}}"
                                    CornerRadius="5"
                                    BorderThickness="1"
                                    BorderBrush="Gray"
                                    Margin="0, 0, 5, 0"/>
                            </Viewbox>
                            <TextBox 
                                x:Name="textBox"
                                Grid.Column="1" 
                                Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Button Grid.Column="2" Content="..." Command="{TemplateBinding BrowseCommand}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:BrushPicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BrushPicker}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <Viewbox Grid.Column="0" Height="{Binding ElementName=textBox, Path=ActualHeight, Mode=OneWay}">
                                <Border 
                                    Width="20" 
                                    Height="20" 
                                    Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=OneWay}"
                                    CornerRadius="5"
                                    BorderThickness="1"
                                    BorderBrush="Gray"
                                    Margin="0, 0, 5, 0"/>
                            </Viewbox>
                            <TextBox 
                                x:Name="textBox"
                                Grid.Column="1" 
                                Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                                IsReadOnly="{TemplateBinding IsReadOnly}"/>
                            <Button Grid.Column="2" Content="..." Command="{TemplateBinding BrowseCommand}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:WindowPartThumb}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WindowPartThumb}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style TargetType="{x:Type local:WindowIcon}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WindowIcon}">
                    <Image Source="{TemplateBinding local:WindowIcon.Icon}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:WindowTitleBar}" BasedOn="{StaticResource {x:Type local:WindowPartThumb}}">
        <Setter Property="Padding" Value="2"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:WindowTitleBar}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid Height="Auto">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <local:WindowIcon Grid.Column="0" VerticalAlignment="Stretch" Width="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualHeight}" Margin="0, 0, 4, 0"/>
                            <ContentPresenter Grid.Column="1" Content="{TemplateBinding Title}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="Center"/>
                            <local:WindowMinimizeButton Grid.Column="2"/>
                            <local:WindowMaximizeButton Grid.Column="3"/>
                            <local:WindowCloseButton Grid.Column="4"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:WindowBorder}" BasedOn="{StaticResource {x:Type local:WindowPartThumb}}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ResizeMode}" Value="NoResize">
                <Setter Property="IsEnabled" Value="False"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ResizeMode}" Value="CanMinimize">
                <Setter Property="IsEnabled" Value="False"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
                <Setter Property="IsEnabled" Value="False"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type local:WindowTopBorder}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNS"/>
    </Style>

    <Style TargetType="{x:Type local:WindowBottomBorder}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNS"/>
    </Style>

    <Style TargetType="{x:Type local:WindowLeftBorder}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeWE"/>
    </Style>

    <Style TargetType="{x:Type local:WindowRightBorder}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeWE"/>
    </Style>

    <Style TargetType="{x:Type local:WindowTopLeftCorner}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNWSE"/>
    </Style>

    <Style TargetType="{x:Type local:WindowTopRightCorner}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNESW"/>
    </Style>

    <Style TargetType="{x:Type local:WindowBottomLeftCorner}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNESW"/>
    </Style>

    <Style TargetType="{x:Type local:WindowBottomRightCorner}" BasedOn="{StaticResource {x:Type local:WindowBorder}}">
        <Setter Property="Cursor" Value="SizeNWSE"/>
    </Style>


    <Style TargetType="{x:Type local:WindowTitleBarButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Width" Value="16"/>
        <Setter Property="Height" Value="16"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                        <Image>
                            <Image.Source>
                                <DrawingImage>
                                    <DrawingImage.Drawing>
                                        <GeometryDrawing Geometry="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Content, Mode=OneWay}" Brush="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Foreground, Mode=OneWay}"/>
                                    </DrawingImage.Drawing>
                                </DrawingImage>
                            </Image.Source>
                        </Image>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:WindowMinimizeButton}" BasedOn="{StaticResource {x:Type local:WindowTitleBarButton}}">
        <Setter Property="Content" Value="{StaticResource MinimizeWindowGeometry}"/>

        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ResizeMode}" Value="NoResize">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type local:WindowMaximizeButton}" BasedOn="{StaticResource {x:Type local:WindowTitleBarButton}}">
        <Setter Property="Content" Value="{StaticResource MaximizeWindowGeometry}"/>

        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Window.WindowState}" Value="Maximized">
                <Setter Property="Content" Value="{StaticResource NormalizeWindowGeometry}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ResizeMode}" Value="NoResize">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=ResizeMode}" Value="CanMinimize">
                <Setter Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type local:WindowCloseButton}" BasedOn="{StaticResource {x:Type local:WindowTitleBarButton}}">
        <Setter Property="Content" Value="{StaticResource CloseWindowGeometry}"/>
    </Style>

</ResourceDictionary>
